home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * ObjectMacZapp -- a standard Mac OOP application template
- *
- *
- *
- * ZShowOffApplication.cpp -- the demo application
- *
- *
- *
- *
- *
- * © 1996, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
- #include "ZShowOffApplication.h"
- #include "MacZoop.h"
- #include "ZGWorldWindow.h"
- #include "ZDialog.h"
- #include "ZProgress.h"
- #include "ZFolderScanner.h"
- #include "ZSortTestWindow.h"
-
- #ifdef APPEARANCE_MGR_AWARE
- #include "ZAMDialog.h"
- #endif
-
-
- /*--------------------------------*** CONSTRUCTOR ***---------------------------------*/
-
-
- ZShowOffApplication::ZShowOffApplication()
- : ZApplication()
- {
- // this application can open TEXT and PICT files
-
- AddFileType('TEXT');
- AddFileType('PICT');
-
- anFType = 'PICT';
- }
-
-
-
- void ZShowOffApplication::StartUp()
- {
- gMenuBar->NominateWindowsMenu( 132 );
- }
-
-
- /*------------------------------*** MAKENEWWINDOW ***---------------------------------*/
- /*
-
- makes a document window of type ZGWorldWindow or ZSortTestWindow according to the filetype
- picked.
-
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::MakeNewWindow()
- {
- if (anFType == 'PICT')
- FailNIL(mostRecent = new ZGWorldWindow( this, kUntitledWindowID ));
- else
- FailNIL(mostRecent = new ZSortTestWindow( this, kUntitledWindowID ));
-
- try
- {
- mostRecent->InitZWindow();
- }
- catch(OSErr err)
- {
- ForgetObject(mostRecent);
-
- throw err;
- }
- }
-
-
- /*--------------------------------*** NEWFLOATER ***----------------------------------*/
- /*
- makes a new floating window, to demonstrate this cool new feature!
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::NewFloater()
- {
- FailNIL( mostRecent = new ZWindow( this, kFloaterID ));
-
- try
- {
- mostRecent->InitZWindow();
-
- }
- catch( OSErr err )
- {
- ForgetObject( mostRecent );
-
- throw err;
- }
-
- mostRecent->Select();
- }
-
-
- /*-------------------------------*** UPDATEMENUS ***---------------------------------*/
- /*
-
- Enable the dialog demo menu items
-
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::UpdateMenus()
- {
- // enable the menus
-
- gMenuBar->EnableCommand( kCmdOpenMoveableModal );
- gMenuBar->EnableCommand( kCmdOpenModal );
- gMenuBar->EnableCommand( kCmdOpenModeless );
- gMenuBar->EnableCommand( kCmdTestProgress );
- gMenuBar->EnableCommand( kCmdScanFolder );
- gMenuBar->EnableCommand( kCmdNewFloater );
-
- inherited::UpdateMenus();
- }
-
-
-
- /*-------------------------------*** HANDLECOMMAND ***--------------------------------*/
- /*
-
- handle the menu items for dialog demo
-
- ----------------------------------------------------------------------------------------*/
-
-
- void ZShowOffApplication::HandleCommand( const long aCmd )
- {
- switch ( aCmd )
- {
- case kCmdOpenMoveableModal:
- OpenDialog( kDialog1 );
- break;
- case kCmdOpenModal:
- OpenDialog( kDialog2 );
- break;
- case kCmdOpenModeless:
- OpenDialog( kDialog3 );
- break;
- case kCmdTestProgress:
- TestProgress();
- break;
- case kCmdScanFolder:
- TestScan();
- break;
- case kCmdNewFloater:
- NewFloater();
- break;
- }
-
- // ask base class to handle any other menu commnds
-
- inherited::HandleCommand( aCmd );
- }
-
-
- /*----------------------------------*** OPENFILE ***----------------------------------*/
- /*
- make sure we create the right sort of window for the file type chosen
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::OpenFile( const FSSpec& aFile, const OSType fType)
- {
- anFType = fType;
-
- inherited::OpenFile( aFile, fType );
- }
-
-
- /*--------------------------------*** TESTPROGRESS ***--------------------------------*/
- /*
-
- this shows how to use the progress dialog class (ZProgress)
- ----------------------------------------------------------------------------------------*/
-
- #define kLoops 500
-
-
- void ZShowOffApplication::TestProgress()
- {
- // make the progress dialog object on the heap
-
- ZProgress aPD (this, kStdProgressResID, kLoops, kProportionalProgress, kCancelType);
-
- long loop;
-
- // caller has responsibility to set the animated cursor
-
- SetBeachBallCursor();
-
- // wait two seconds before showing the dialog
-
- aPD.SetDelay(kTwoSeconds);
- aPD.SetMessage("\pLooping 500 times...");
-
- // loop <kLoops> times, updating the progress and
- // aborting if the user cancelled
-
- for (loop = 0; loop < kLoops; loop++)
- {
- if (! aPD.InformProgress(loop))
- break;
- }
-
- // when the dialog goes out of scope now, it will be automatically deleted
- // and the chain of command maintained accordingly. Neat, huh?
- }
-
-
-
-
- /*---------------------------------*** OPENDIALOG ***---------------------------------*/
- /*
-
- construct dialog windows with the ID passed- used to demonstrate dialogs
-
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::OpenDialog(short id)
- {
- ZDialog* aDialog;
-
- #ifdef APPEARANCE_MGR_AWARE
-
- if ( gMacInfo.hasAppearanceMgr )
- FailNIL( aDialog = new ZAMDialog( this, id ));
- else
- FailNIL(aDialog = new ZDialog(this, id));
-
- #else
- FailNIL(aDialog = new ZDialog(this, id));
- #endif
-
- try
- {
- aDialog->InitZWindow();
- }
- catch(OSErr err)
- {
- ForgetObject(aDialog);
-
- throw err;
- }
-
- // show the window and make it active
-
- aDialog->Select();
- }
-
-
- /*-----------------------------------*** TESTSCAN ***---------------------------------*/
- /*
- demonstrate the folder scanner- this scans every file in the selected folder.
-
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::TestScan()
- {
- ZFolderScanner aScanner; // make object on the stack
-
- if (aScanner.PickFolder())
- {
- SetBeachBallCursor(); // animate cursor
-
- aScanner.SetSearchDepth(-1); // search every folder.
- aScanner.ScanFolder(); // do the scan
- }
- }
-
-